package com.inkyi.assistant.app.base;

import com.formdev.flatlaf.FlatLightLaf;
import com.inkyi.framework.daqian.share.utils.SwingUtils;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.util.Enumeration;

public class BaseFrame extends JFrame {

    static {
        FlatLightLaf.setup();
    }

    //设置全局字体
    public static void initGlobalFontSetting(Font fnt) {
        FontUIResource fontRes = new FontUIResource(fnt);
        for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements(); ) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource)
                UIManager.put(key, fontRes);
        }
    }

    public BaseFrame(String title, int width, int height) {
        // 设置 JFrame 的基本属性。
        this.setTitle(title);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(width, height);
        //设定大小不能超过屏幕尺寸
        Dimension dimension = SwingUtils.calculateWindowSize(AppConstant.DEFAULT_SIZE);
        this.setSize(dimension);
        //接着计算窗口的中心位置，将窗口移动到屏幕中心
        Point screenCenter = SwingUtils.calculateWindowCenter(AppConstant.DEFAULT_SIZE);
        this.setLocation(screenCenter);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public BaseFrame() {
        this("Base Frame", 1300, 800);
    }
}
